package com.neu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.PostMapper;
import com.neu.po.Dept;
import com.neu.po.Post;
import com.neu.po.PostExample;
import com.neu.po.PostExample.Criteria;

@Service
public class PostServiceImpl implements PostService {

	@Autowired
	private PostMapper postMapper;
	
	@Override
	public int insert(Post post) {
		// TODO Auto-generated method stub
		return postMapper.insert(post);
	}

	@Override
	public int update(Post post) {
		// TODO Auto-generated method stub
		return postMapper.updateByPrimaryKey(post);
	}

	@Override
	public int delete(int id) {
		// TODO Auto-generated method stub
		return postMapper.deleteByPrimaryKey(id);
	}


	@Override
	public List<Post> getAll() {
		PostExample example = new PostExample();
		
		return postMapper.selectByExample(example);
	}

	@Override
	public List<Post> getByName(String pname) {
		PostExample example = new PostExample();
		
		example.or().andPnameEqualTo(pname);
		
		return postMapper.selectByExample(example);
	}

	@Override
	public PageInfo<Post> getPaged(int pageSize, int pageNum, String keyword) {
		PostExample example = new PostExample();
		
		Criteria c1 = example.createCriteria();
		
		c1.andPnameLike("%"+keyword+"%");
		
		PageHelper.startPage(pageNum, pageSize);
		
		List<Post> list = postMapper.selectByExample(example);
		
		PageInfo<Post> pageInfo = new PageInfo<>(list);
		
		
		return pageInfo;
	}

}
